BattleConfig = {}
local this = BattleConfig

function BattleConfig.init()
	this.gameObject = nil
	this.leftNode = nil
	this.rightNode = nil
	this.leftNodeTransform = nil
	this.rightNodeTransform = nil
end

function BattleConfig.registerRoot(gameObject)
	this.gameObject = gameObject
	local transform = this.gameObject:GetComponent(typeof(UnityEngine.Transform))

	this.leftNode = transform:Find("Left")
	this.rightNode = transform:Find("Right")

	this.leftNodeTransform = this.leftNode:GetComponent(typeof(UnityEngine.Transform))
	this.rightNodeTransform = this.rightNode:GetComponent(typeof(UnityEngine.Transform))
end

function BattleConfig.clear()
	this.gameObject = nil
	this.leftNode = nil
	this.rightNode = nil
	this.leftNodeTransform = nil
	this.rightNodeTransform = nil
end

function BattleConfig.getFormationPos(isLeft, formationId)
	local rootTransform = nil
	if(isLeft) then
		rootTransform = this.leftNodeTransform
	else
		rootTransform = this.rightNodeTransform
	end

	local positionTbl = {}

	local formationName = "Formation"..formationId
	local formationNode = rootTransform:Find(formationName)
	local formationNodeTransform = formationNode:GetComponent(typeof(UnityEngine.Transform))
	local childCount = formationNodeTransform.childCount
	for i=1,childCount do
		local indexName = "Index"..i
		local indexNode = formationNodeTransform:Find(indexName)
		local indexNodeTransform = indexNode:GetComponent(typeof(UnityEngine.Transform))
		table.insert(positionTbl, indexNodeTransform.position)
	end

	return positionTbl
end


--[[
function BattleConfig:ctor(...)
	local arg = {...}
	self.gameObject = arg[1]
	local transform = self.gameObject:GetComponent(typeof(UnityEngine.Transform))
	local left = transform:Find("left")
	local right = transform:Find("right")
	if(left == nil or right == nil) then
		GameLog.Warning("_Config doesn't have left or right child node!")
	end

	self.left = left
	self.right = right
	self.deltaX = 2.5
	self.deltaY = 1.5
end

function BattleConfig.Start(gameObject)
	local object = BattleConfig.new(gameObject)

	if(Battle.BattleConfig ~= nil) then
		GameLog.Warning("scene has multiple BattleConfig!")
	end

	--object.gameObject = gameObject
	Battle.BattleConfig = object

	return object
end

function BattleConfig.Destroy(gameObject, object)
	object = nil
end

function BattleConfig:getPos(isFriend, index)
	local pos = Vector3.New(0,0,0)
	if(isFriend) then
		pos.z = self.left.position.z
		if(index==1) then
			pos.x = self.left.position.x + self.deltaX
			pos.y = self.left.position.y + self.deltaY
		elseif(index==2) then
			pos.x = self.left.position.x + self.deltaX
			pos.y = self.left.position.y - self.deltaY
		elseif(index==3) then
			pos.x = self.left.position.x
			pos.y = self.left.position.y
		elseif(index==4) then
			pos.x = self.left.position.x - self.deltaX
			pos.y = self.left.position.y + self.deltaY
		elseif(index==5) then
			pos.x = self.left.position.x - self.deltaX
			pos.y = self.left.position.y - self.deltaY
		end
	else
		pos.z = self.right.position.z
		if(index==1) then
			pos.x = self.right.position.x - self.deltaX
			pos.y = self.right.position.y + self.deltaY
		elseif(index==2) then
			pos.x = self.right.position.x - self.deltaX
			pos.y = self.right.position.y - self.deltaY
		elseif(index==3) then
			pos.x = self.right.position.x
			pos.y = self.right.position.y
		elseif(index==4) then
			pos.x = self.right.position.x + self.deltaX
			pos.y = self.right.position.y + self.deltaY
		elseif(index==5) then
			pos.x = self.right.position.x + self.deltaX
			pos.y = self.right.position.y - self.deltaY
		end
	end	

	return pos
end

return BattleConfig

]]